package com.lm.ddd.presentation;

import com.lm.ddd.application.OrderService;
import com.lm.ddd.domain.model.Order;
import com.lm.ddd.infrastructure.InMemoryOrderRepository;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
public class OrderController {
    // 为了简单示例，直接在控制器中构造依赖
    private final OrderService orderService;
    private final InMemoryOrderRepository orderRepository;

    public OrderController() {
        // 依赖注入通常由 Spring 完成，这里简单实例化
        this.orderRepository = new InMemoryOrderRepository();
        this.orderService = new OrderService(orderRepository);
    }

    // 查询订单
    @GetMapping("/{orderId}")
    public Order getOrder(@PathVariable String orderId) {
        return orderRepository.findById(orderId);
    }

    // 支付订单
    @PostMapping("/{orderId}/pay")
    public String payOrder(@PathVariable String orderId) {
        orderService.payOrder(orderId);
        return "订单支付成功";
    }
}